<template>
  <div id="awardwinning">  

     <el-form ref="form"  label-width="80px">           
          <el-row>
            <el-col :span="12" >  
                <div style="height:38px;line-height:38px;width:150px;"> 
                  <i class="el-icon-back" @click="goBack"></i> 
                  {{ $route.query.name }} 
                </div> 
            </el-col>
          </el-row>
    </el-form>

     <el-row>
        <el-col :span="24" style="text-align: right;">         
            <el-button type="primary" class="custom_color_button" style="margin-bottom:10px;" @click="mtk1_but()">发放奖励</el-button>         
        </el-col>
  </el-row>

   <!-- 渲染数据list -->
   <award-winning-list :datalist="datalist"  @up_list_fun="list_fun"> </award-winning-list>

      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>


       <!-- 发放奖励 -->
    <el-dialog title="发放奖励" :visible.sync="mtk1"  width="400px">
        <div style="width:100%;"> 
           <el-form ref="form"   label-width="75px" style="width:100%;">  

             <el-form-item label="选择日期" style="width:100%;">
                 <el-date-picker type="datetime" placeholder="选择日期" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"  v-model="mtk1_form.time"  style="width:100%;"></el-date-picker>
            </el-form-item>   
            <el-form-item label="奖励类型">
                <el-select  v-model="mtk1_form.select_num" placeholder="请选择"  style="width:100%;">
                    <el-option  v-for="(item,index) in select_data" :key="index" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="价格">
                    <el-input v-model="mtk1_form.price" placeholder="价格"></el-input>
            </el-form-item> 

            </el-form>
            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;" @click="mtk1_qr_but()">确认</el-button>
            </div>
        </div> 
    </el-dialog>       
  </div>
</template>

<script>
import AwardWinningList from '@/view/Marketing/AwardWinningList'
export default {
  name: 'awardwinning',
  data () {
    return {
        datalist:[],
        page:1,
        count:0,
        mkid:'',
        mtk1:false,
        mtk1_form:{
           select_num:1,
           price:'',
           time:''
        },
        select_data:[{"name":"金蛋","id":1},{"name":"彩蛋","id":2}]
    }
  },
 components:{
    AwardWinningList
  },
  created(){
       
       this.mkid  = this.$route.query.mkid
       this.list_fun()
  },
  mounted (){
    
  },
  methods: {
     list_fun(){
        this.post("/marketer/listOfWinPrizeLog", {
            mkid:this.mkid,
            page:this.page
        }).then(res => {  
            //console.log(res)
            this.count = res.result.count
            this.datalist = res.result.list

        })
     },
     mtk1_but(){
       this.mtk1 = true
     },
     mtk1_qr_but(){
          this.post("/marketer/addWinPrizeLog", {
               mkid:this.mkid,
               type:this.mtk1_form.select_num,
               price:this.mtk1_form.price,
               time:this.mtk1_form.time,
	        }).then(res => {
                //console.log(res)
             if(res.error_code == 0){
                        this.open1(res.result,'success')  
                        this.mtk1 = false
                        this.list_fun()
                }else {
                      this.open1(res.message,'warning') 
                }

         })
     },
     goBack() {
        this.$router.go(-1)
    },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>
</style>
